<?php

if(isset($_POST['submit'])) {
/*$databasehost = "localhost";
$databasename = "signinventory";
$databasetable = "Sign_Posts";
$databaseusername ="root";
$databasepassword = "";*/

$link = mysql_connect("localhost","webapp-devel","nd8h3EH8fh3");
mysql_select_db('test',$link);

$file = $_FILES['file']['name'];
	$fieldseparator = ",";
	$lineseparator = "\n";

	 if(!empty($file)) {
 				$csvfile = @$_FILES['file']['tmp_name'];
				
				
 


				$file = fopen($csvfile,"r");
				

while (!feof($file) ) {

$line_of_text = fgetcsv($file, 1024);

 $insert = sprintf("INSERT INTO `Sign_Posts` (sp_catalog_item_yesno,sp_longitude,sp_latitude) 
								VALUES ('%d','%f','%f')",
										'2',
										$line_of_text[0],
										$line_of_text[1]);
														



mysql_query($insert);
														//echo $line_of_text[1];

}

fclose($file);


/*
				$size = filesize($csvfile);
				$csvcontent = fread($file,$size);
				
				fclose($file);
				
				$lines = 0;
				$queries = "";
				$linearray = array();
				
				foreach(split($lineseparator,$csvcontent) as $line) {
				
					$lines++;
					$line = trim($line," \t");
					
					$line = str_replace("\r","",$line);
					
					$line = str_replace("'","\'",$line);
					
					$linearray = explode($fieldseparator,$line);
					  echo $linearray[2]."<br/>";*/
	/*if(!empty($linearray[7])) { 
	$qryDonotCall = mysql_query("SELECT * FROM `donotcalllist` WHERE `phoneNumber` = '".$linearray[7]."'");
	if(mysql_num_rows($qryDonotCall) == 0) {
	$nameData = $linearray[0]." ".$linearray[1];
					$insert = sprintf("INSERT INTO `leads` (name,
												 address,
												 city,
												 province,
												 postcode,
												 phoneNumber,
												 age,
												 sex,
												 income,
												 ownership,
												 language,
												 dwellingAge,
												 dwellingType,
												 leadCreatedDate) 
								VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", 
										$nameData,
										mysql_real_escape_string($linearray[2]),
										mysql_real_escape_string($linearray[4]),
										mysql_real_escape_string($linearray[5]),
										mysql_real_escape_string($linearray[6]),
										mysql_real_escape_string($linearray[7]),
										mysql_real_escape_string($linearray[9]),
										mysql_real_escape_string($linearray[10]),
										mysql_real_escape_string($linearray[8]),
										mysql_real_escape_string($linearray[11]),
										mysql_real_escape_string($linearray[12]),
										mysql_real_escape_string($linearray[18]),
										mysql_real_escape_string($linearray[19]),
										$date);
				mysql_query($insert);
				}
			}*/
				
			//}
			
}

//@mysql_close($con);


echo "Found a total of $lines records in this csv file.\n";

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" name="excel" enctype="multipart/form-data" action="">
<input type="file" name="file" size="30" />
<input type="submit" name="submit" value="submit" />
</form>

</body>
</html>
